<template>
	<view class="main">
		<gui-a-header title="通知详情"></gui-a-header>
		<view class="title_box gui-flex gui-justify-content-center">
			<view class="title">
				{{detailData.title}}
			</view>
		</view>
		<mp-html :content="$u.richImg(detailData.context)" />
		<view class="footer gui-flex gui-column gui-align-items-end">
			<view class="f24">
				{{detailData.creBy}}
			</view>
			<view class="f24 mt15">
				{{detailData.createTime}}
			</view>
		</view>
		<view class="btn_warp" v-if="detailData.type ==6 && detailData.messageType == 0">
			<button class="saveBtn" @click="sumbit(1)">同意</button>
			<button class="saveBtn refuse mt40" @click="sumbit(2)">拒绝</button>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive,
		inject
	} from 'vue'
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import {
		selectUserMessageInfo,
		userMessageUpdateInfo
	} from '@/api/user.js';
	
	const $u = reactive(inject('$u'))
	const policyId = ref('');
	const detailData = ref({
		context: ''
	})
	onLoad((option) => {
		console.log(option);
		if (option.id) {
			policyId.value = option.id;
			loadDetail();
		}
	})
	
	const loadDetail = () => {
		selectUserMessageInfo({
			id: policyId.value
		}).then(res => {
			if(res.code == 200) {
				detailData.value = res.data;
				console.log(detailData.value);
			}
		})
	}
	
	const sumbit = (messageType) => {
		userMessageUpdateInfo({
			id: policyId.value,
			messageType
		}).then(res => {
			if(res.code == 200) {
				$u.msg('操作成功')
				detailData.value.messageType = messageType;
				uni.$emit('updateNotic')
			}
		})
	}
</script>

<style lang="scss">
.main {
	padding: 60rpx;
}

.title_box {
	margin-bottom: 30rpx;
}

.title {
	width: 500rpx;
	font-weight: bold;
	font-size: 32rpx;
	color: #323232;
	text-align: center;
}

.footer {
	margin-top: 44rpx;
	color: #555555;
}
.mt15 {
	margin-top: 15rpx;
}

.btn_warp {
	margin-top: 80rpx;
}
.refuse {
	background: #FF3D00;
}
</style>
